// packageF/new_info_v2/components/pop-up.js
let app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    popUpType: '',
    popUpTitle: '',
    dataList: [],
    alipayForm: { //支付宝
      alipay: '',
      alipayname: ''
    },
    weChatForm: { //微信
      wechat: ''
    },
    email:''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    checkShow() { //弹出弹窗
      this.setData({
        show: true
      })
    },
    stateChanges(e) {
      if (e == "alipay") {
        this.setData({
          popUpType: e,
          popUpTitle: "支付宝账号"
        })
      } else if (e == "weChat") {
        this.setData({
          popUpType: e,
          popUpTitle: "微信号"
        })
      } else if (e == 'email') {
        this.setData({
          popUpType: e,
          popUpTitle: "邮箱"
        })
      }
    },
    onClose() { //关闭弹窗
      this.setData({
        show: false
      });
    },
    confirm() { //弹窗确定 
      var that = this;
      let url = '';
      let json = {};
      if (this.data.popUpType == 'alipay') {
        if (app._isTextEmpty(this.data.alipayForm.alipay)) {
          wx.showToast({
            icon: 'none',
            title: '请输入账号',
            duration: 1500
          });
          return
        }
        if (app._isTextEmpty(this.data.alipayForm.alipayname)) {
          wx.showToast({
            icon: 'none',
            title: '请输入姓名',
            duration: 1500
          });
          return
        }
        url = 'member.member-info.change-alipay-info'
        json = this.data.alipayForm
      } else if (this.data.popUpType == 'weChat') {
        if (app._isTextEmpty(this.data.weChatForm.wechat)) {
          wx.showToast({
            icon: 'none',
            title: '请输入账号',
            duration: 1500
          });
          return
        }
        url = 'member.member-info.change-wechat'
        json = this.data.weChatForm
      } else if (this.data.popUpType == 'email'){
        if (app._isTextEmpty(this.data.email)) {
          wx.showToast({
            icon: 'none',
            title: '请输入邮箱',
            duration: 1500
          });
          return
        }
        url = 'member.member-info.changeEmail'
        json = {
          email:this.data.email
        }
      }
      let urlStr = app.getNetAddresss(url);
      app._getNetWork({
        url: urlStr,
        data: json,
        success: (resdata) => {
          let res = resdata.data
          if (res.result == 1) {
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1500
            });
            that.childGetData();
            this.setData({
              show: false
            })
          } else {
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1500
            });
          }
        },
        fail: function (res) {
          console.log(res);
        }
      });
    },
    childGetData() {
      this.triggerEvent('childGetData'); //如果需要传递参数，直接写在triggerEvent的参数里即可
    },
    onChange(e) { //输入框值双向绑定
      if (e.currentTarget.dataset.typevalue == "alipay") {
        this.setData({
          'alipayForm.alipay': e.detail
        })
      } else if (e.currentTarget.dataset.typevalue == "wechat") {
        this.setData({
          'weChatForm.wechat': e.detail
        })
      } else if (e.currentTarget.dataset.typevalue == "alipayname") {
        this.setData({
          'alipayForm.alipayname': e.detail
        })
      } else if (e.currentTarget.dataset.typevalue == "email") {
        this.setData({
          email:e.detail
        })
      }
    },

    assignment(name, value) { //属性赋值
      this.setData({
        [name]: value
      })
    }
  }
})